//
//  ViewController.swift
//  MultiLanguage
//
//  Created by macvivi on 2022/3/20.
//

import UIKit

class ViewController: UIViewController {
    
    
    @IBOutlet var languageLabel: UILabel!
    @IBOutlet var chineseBtn: UIButton!
    @IBOutlet var englishBtn: UIButton!
    @IBOutlet var autoBtn: UIButton!
    
    func setupUI(){
        
        languageLabel.text = LocalizableManager.localValue("english")
        chineseBtn.setTitle(LocalizableManager.localValue("chinese"), for: .normal)
        englishBtn.setTitle(LocalizableManager.localValue("english"), for: .normal)
        autoBtn.setTitle(LocalizableManager.localValue("auto"), for: .normal)
    }
    
    
    @IBAction func chineseBtnClick(_ sender: UIButton) {
        LocalizableManager.setLanguage(.chinese)
    }
    
    @IBAction func englishBtnClick(_ sender: Any) {
        LocalizableManager.setLanguage(.english)
    }
    
    @IBAction func autoBtnClick(_ sender: Any) {
        LocalizableManager.setLanguage(.auto)
    }
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()
        NotificationCenter.default.addObserver(forName: NSNotification.Name(rawValue: "languageChanged"), object: nil,  queue: nil) { (notification) in
            self.setupUI()
        }
    }
    
  


}

